home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / comm1 / mgplp378.lha / magplip / source / port.asm < prev    next >
Assembly Source File  |  1996-03-29  |  12KB  |  342 lines

  1. ;
  2. ;  $VER: port.asm 1.6 (29 Mar 1996)
  3. ;
  4. ;  magplip.device - Parallel Line Internet Protocol
  5. ;
  6. ;  Assembler routines for efficient port handling.
  7. ;
  8. ;  Original code written by Oliver Wagner and Michael Balzer.
  9. ;
  10. ;  This version has been completely reworked by Marius Gröger, introducing
  11. ;  slight protocol changes. The new source is a lot better organized and
  12. ;  maintainable.
  13. ;
  14. ;  Additional changes and code cleanup by Jan Kratochvil and Martin Mares.
  15. ;  The new source is significantly faster and yet better maintainable.
  16. ;
  17. ;  (C) Copyright 1993-1994 Oliver Wagner & Michael Balzer
  18. ;  (C) Copyright 1995 Jan Kratochvil & Martin Mares
  19. ;  (C) Copyright 1995-1996 Marius Gröger
  20. ;      All Rights Reserved
  21. ;
  22. ;  $HISTORY:
  23. ;
  24. ;  29 Mar 1996 : 001.006 :  changed copyright note
  25. ;  24 Feb 1996 : 001.005 :  + added PRTRSEL data direction signal
  26. ;                           + minor re-arrangements
  27. ;  30 Dec 1995 : 001.004 :  support for single frame buffer
  28. ;  05 Dec 1995 : 001.003 :  + short branches explicitly coded as such
  29. ;                           + some condition jumps which were effectively
  30. ;                             unconditional changed to bra's
  31. ;  30 Aug 1995 : 001.002 :  support for timer-timed timeout :-)
  32. ;  20 Aug 1995 : 001.001 :  + removed need for conditional compiling, as we
  33. ;                             we want a generic, symmetrical code
  34. ;                           + in interrupt handlers, A6 points already to
  35. ;                             SysBase
  36. ;                           + using JSRLIB/JMPLIB macros
  37. ;                           + removed implicit some assumptions on the values
  38. ;                             behind symbolic names
  39. ;  13 Feb 1995 : 001.000 :  created (in fact manually compiled from 'C'-
  40. ;                           original) (jk/mm)
  41. ;
  42.       section "text",code
  43.  
  44.  
  45. ;----------------------------------------------------------------------------
  46.  
  47.  
  48.       IFND HARDARE_CIA_I
  49.       include "hardware/cia.i"
  50.       ENDC
  51.  
  52.       IFND EXEC_MACROS_I
  53.       include "exec/macros.i"
  54.       ENDC
  55.  
  56.       IFND MAGPLIP_I
  57.       include "magplip.i"
  58.       ENDC
  59.  
  60.  
  61. ;----------------------------------------------------------------------------
  62.  
  63.  
  64.       xref    _CRC16
  65.  
  66.       xdef    _interrupt
  67.       xdef    _hwsend
  68.       xdef    _hwrecv
  69.  
  70. ;----------------------------------------------------------------------------
  71.  
  72. ciaa     equ     $bfe001
  73. ciab     equ     $bfd000
  74. BaseAX   equ     ciab+ciapra
  75.  
  76.  
  77. SETCIAOUTPUT MACRO
  78.       bset     #CIAB_PRTRSEL,ciab+ciapra-BaseAX(a5)   ; raise PRTSEL line
  79.       st       ciaa+ciaddrb-BaseAX(\1)                ; data dir. => output
  80.       ENDM
  81.  
  82. SETCIAINPUT MACRO
  83.       bclr     #CIAB_PRTRSEL,ciab+ciapra-BaseAX(a5)   ; lower PRTSEL line
  84.       sf       ciaa+ciaddrb-BaseAX(\1)                ; data dir. => input
  85.       ENDM
  86.  
  87.  
  88. ;----------------------------------------------------------------------------
  89. ;
  90. ; NAME
  91. ;     interrupt() - ICR FLG interrupt handler
  92. ;
  93. ; SYNOPSIS
  94. ;     void interrupt(struct PLIPBase *)
  95. ;                    A1
  96. ;
  97. ; FUNCTION
  98. ;     This is called from CIA resource on the receipt of an parallel port
  99. ;     FLG line interrupt. This is the case if the other side starts
  100. ;     transmission and writes the first byte to our port.
  101. ;
  102. ;     We recognise this here and propagate the information to the server
  103. ;     task by Signal()ing it and by setting the PLIPB_RECEIVING bit
  104. ;     in the flags field.
  105. ;
  106. _interrupt:
  107.         btst    #PLIPB_RECEIVING,pb_Flags(a1)
  108.         bne.s   skipint
  109.         move.b  pb_HandshakeBit+HS_LINE(a1),d0
  110.         btst    d0,ciab+ciapra
  111.         beq.s   skipint
  112.         bset    #PLIPB_RECEIVING,pb_Flags(a1)
  113.         move.l  pb_IntSigMask(a1),d0
  114.         move.l  pb_Server(a1),a1
  115.         JMPLIB  Signal
  116. skipint rts
  117.  
  118. ;----------------------------------------------------------------------------
  119. ;
  120. ; NAME
  121. ;     hwsend() - low level send routine
  122. ;
  123. ; SYNOPSIS
  124. ;     void hwsend(struct PLIPBase *)
  125. ;                  A0
  126. ;
  127. ; FUNCTION
  128. ;     This routine sends the PLIPBase->pb_Frame to the other side. It
  129. ;     cares for CRC encoding, if wanted. The frame header will be
  130. ;     set up except of the pf_Size field, which must be pre-initialized.
  131. ;
  132. _hwsend:
  133.          movem.l  d2-d7/a2-a6,-(sp)
  134.          move.l   a0,a2                               ; a2 = PLIPBase
  135.          moveq    #FALSE,d2                           ; d2 = return value
  136.          moveq    #0,d3
  137.          move.l   d3,d4
  138.          move.b   pb_HandshakeBit+HS_REQUEST(a2),d3   ; d3 = HS_REQUEST
  139.          move.b   pb_HandshakeBit+HS_LINE(a2),d4      ; d4 = HS_LINE
  140.          move.l   pb_Frame(a2),a4                     ; a4 = Frame
  141.  
  142.          ;
  143.          ; CRC wanted ?
  144.          ;
  145.          btst     #PLIPB_SENDCRC,pb_Flags(a2)
  146.          beq.s    hww_NoCRC
  147.          ; yes
  148.          move.w   #SYNCWORD_CRC,pf_Sync(a4)
  149.          lea      PLIPFrame_SIZE(a4),a0
  150.          move.w   pf_Size(a4),d0
  151.          subq.w   #PKTFRAMESIZE_2,d0
  152.          jsr      _CRC16(pc)
  153.          move.w   d0,pf_CRC(a4)
  154.          bra.s    hww_CRC
  155.  
  156. hww_NoCRC:
  157.          move.w   #SYNCWORD_NOCRC,pf_Sync(a4)
  158.  
  159. hww_CRC  move.l   pb_CIAABase(a2),a6
  160.          moveq    #CIAICRF_FLG,d0
  161.          JSRLIB   AbleICR                             ; DISABLEINT
  162.          lea      BaseAX,a5
  163.          SETCIAOUTPUT a5
  164.          move.b   (a5),d7                             ; SAMPLEINPUT, d7 = State
  165.          move.l   a4,a3
  166.          move.w   pf_Size(a4),d6
  167.          addq.w   #PKTFRAMESIZE_1-2,d6
  168.          move.b   (a3)+,ciaa+ciaprb-BaseAX(a5)        ; WRITECIA *p++
  169. hww_LoopShake1:
  170.          move.b   (a5),d0                             ; ciab+ciapra
  171.          eor.b    d7,d0
  172.          btst     d4,d0                               ; WAITINPUTTOGGLE
  173.          bne.s    hww_cont1
  174.          tst.b    pb_TimeoutSet(a2)
  175.          beq.s    hww_LoopShake1
  176.          bra.s    hww_TimedOut
  177. hww_cont1:
  178.          eor.b    d0,d7
  179.  
  180. hww_MainLoop:
  181.          move.b   (a3)+,ciaa+ciaprb-BaseAX(a5)        ; WRITECIA *p++
  182.          bchg     d3,(a5)                             ; OUTPUTTOGGLE
  183. hww_LoopShake2:
  184.          move.b   (a5),d0                             ; ciab+ciapra
  185.          eor.b    d7,d0
  186.          btst     d4,d0                               ; WAITINPUTTOGGLE
  187.          bne.s    hww_cont2
  188.          tst.b    pb_TimeoutSet(a2)
  189.          beq.s    hww_LoopShake2
  190.          bra.s    hww_TimedOut
  191. hww_cont2:
  192.          eor.b    d0,d7
  193.          dbra     d6,hww_MainLoop
  194.          moveq    #TRUE,d2                            ; rc = TRUE
  195. hww_TimedOut:
  196.          SETCIAINPUT a5
  197.          bclr     d3,(a5)                             ; CLEARREQUEST ciab+ciapra
  198.          moveq    #CIAICRF_FLG,d0
  199.          JSRLIB   SetICR                              ; CLEARINT
  200.          move.w   #CIAICRF_FLG|CIAICRF_SETCLR,d0
  201.          JSRLIB   AbleICR                             ; ENABLEINT
  202.  
  203.          move.l   d2,d0                               ; return rc
  204.          movem.l  (sp)+,d2-d7/a2-a6
  205. Return   rts
  206.  
  207.  
  208. ;----------------------------------------------------------------------------
  209. ;
  210. ; NAME
  211. ;     hwrecv() - low level receive routine
  212. ;
  213. ; SYNOPSIS
  214. ;     void hwrecv(struct PLIPBase *)
  215. ;                 A0
  216. ;
  217. ; FUNCTION
  218. ;     This routine receives a magPLIP frame and stores it into
  219. ;     PLIPBase->pb_Frame. It cares for CRC decoding, if the incoming
  220. ;     packet is encoded. The pf_Size field will indicate the length
  221. ;     of the received data.
  222. ;
  223. _hwrecv:
  224.          movem.l  d2-d7/a2-a6,-(sp)
  225.          move.l   a0,a2                               ; a2 = PLIPBase
  226.          moveq    #FALSE,d5                           ; d5 = return value
  227.          move.l   pb_CIAABase(a2),a6                  ; a6 = CIABase
  228.          moveq    #0,d3
  229.          move.l   d3,d2
  230.          move.b   pb_HandshakeBit+HS_REQUEST(a2),d3   ; d3 = HS_REQUEST
  231.          move.b   pb_HandshakeBit+HS_LINE(a2),d2      ; d2 = HS_LINE
  232.          lea      BaseAX,a5                           ; a5 = ciab+ciapra
  233.          move.l   pb_Frame(a2),a4                     ; a4 = Frame
  234.  
  235.          moveq    #CIAICRF_FLG,d0
  236.          JSRLIB   AbleICR                             ; DISABLEINT
  237.  
  238.          move.b   (a5),d7                             ; SAMPLEINPUT
  239.          cmp.b    #SYNCBYTE_HEAD,ciaa+ciaprb-BaseAX(a5) ; READCIABYTE
  240.          bne      hwr_TimedOut
  241.  
  242.          bchg     d3,(a5)                             ; OUTPUTTOGGLE
  243. hwr_LoopShake1:
  244.          move.b   (a5),d0                             ; ciab+ciapra
  245.          eor.b    d7,d0
  246.          btst     d2,d0                               ; WAITINPUTTOGGLE
  247.          bne.s    hwr_cont1
  248.          tst.b    pb_TimeoutSet(a2)
  249.          beq.s    hwr_LoopShake1
  250.          bra      hwr_TimedOut
  251. hwr_cont1:
  252.          eor.b    d0,d7
  253.          move.b   ciaa+ciaprb-BaseAX(a5),d4           ; READCIABYTE
  254.          bchg     d3,(a5)                             ; OUTPUTTOGGLE
  255.          move.b   d4,d0
  256.          subq.b   #SYNCBYTE_CRC,d0
  257.          bcs.s    hwr_TimedOut
  258.          subq.b   #SYNCBYTE_NOCRC,d0
  259.          bcc.s    hwr_TimedOut
  260.          lea      pf_Size(a4),a3
  261.  
  262.          ; Read 1st length byte
  263.          ;
  264. hwr_LoopShake2
  265.          move.b   (a5),d0                             ; ciab+ciapra
  266.          eor.b    d7,d0
  267.          btst     d2,d0                               ; WAITINPUTTOGGLE
  268.          bne.s    hwr_cont2
  269.          tst.b    pb_TimeoutSet(a2)
  270.          beq.s    hwr_LoopShake2
  271.          bra.s    hwr_TimedOut
  272. hwr_cont2:
  273.          eor.b    d0,d7
  274.          move.b   ciaa+ciaprb-BaseAX(a5),(a3)+        ; READCIABYTE
  275.          bchg     d3,(a5)                             ; OUTPUTTOGGLE
  276.  
  277.          ; Read 2nd length byte
  278.          ;
  279. hwr_LoopShake3:
  280.          move.b   (a5),d0                             ; ciab+ciapra
  281.          eor.b    d7,d0
  282.          btst     d2,d0                               ; WAITINPUTTOGGLE
  283.          bne.s    hwr_cont3
  284.          tst.b    pb_TimeoutSet(a2)
  285.          beq.s    hwr_LoopShake3
  286.          bra.s    hwr_TimedOut
  287. hwr_cont3:
  288.          eor.b    d0,d7
  289.          move.b   ciaa+ciaprb-BaseAX(a5),(a3)+        ; READCIABYTE
  290.          bchg     d3,(a5)                             ; OUTPUTTOGGLE ciab+ciapra
  291.  
  292.          move.w   -2(a3),d6                           ; = length
  293.          subq.w   #PKTFRAMESIZE_2,d6
  294.          bcs.s    hwr_TimedOut
  295.          cmp.w    pb_MTU+2(a2),d6
  296.          bhi.s    hwr_TimedOut
  297.          addq.w   #PKTFRAMESIZE_2-1,d6
  298.  
  299.          ; Read main packet body
  300.          ;
  301. hwr_MainLoop:
  302. hwr_LoopShake4:
  303.          move.b   (a5),d0                             ; ciab+ciapra
  304.          eor.b    d7,d0
  305.          btst     d2,d0
  306.          bne.s    hwr_cont4
  307.          tst.b    pb_TimeoutSet(a2)
  308.          beq.s    hwr_LoopShake4
  309.          bra.s    hwr_TimedOut
  310. hwr_cont4:
  311.          eor.b    d0,d7
  312.          move.b   ciaa+ciaprb-BaseAX(a5),(a3)+        ; READCIABYTE
  313.          bchg     d3,(a5)                             ; OUTPUTTOGGLE ciab+ciapra
  314.          dbra     d6,hwr_MainLoop
  315.  
  316. hwr_DoneRead:
  317.          subq.b   #SYNCBYTE_CRC,d4
  318.          bne.s    hwr_ReadOkay
  319.          lea      PLIPFrame_SIZE(a4),a0
  320.          move.w   pf_Size(a4),d0
  321.          subq.w   #PKTFRAMESIZE_2,d0
  322.          jsr      _CRC16(pc)
  323.          cmp.w    pf_CRC(a4),d0
  324.          bne.s    hwr_TimedOut
  325.  
  326. hwr_ReadOkay:
  327.          moveq    #TRUE,d5
  328. hwr_TimedOut:
  329.          bclr     #PLIPB_RECEIVING,pb_Flags(a2)
  330.          SETCIAINPUT a5
  331.          bclr     d3,(a5)                             ; CLEARREQUEST ciab+ciapra
  332.          moveq    #CIAICRF_FLG,d0
  333.          JSRLIB   SetICR                              ; CLEARINT
  334.          move.w   #CIAICRF_FLG|CIAICRF_SETCLR,d0
  335.          JSRLIB   AbleICR                             ; ENABLEINT
  336.  
  337.          move.l   d5,d0                               ; return value
  338.          movem.l  (sp)+,d2-d7/a2-a6
  339.          rts
  340.  
  341.          end
  342.